home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / comp / callfun.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  2.0 KB  |  74 lines

  1. /*
  2.                             C A L L F U N . C
  3. */
  4.  
  5. #include "iccomp.h"
  6.  
  7. ESTRUC_ *callfun(x, e)
  8.     unsigned
  9.         x;
  10.     ESTRUC_
  11.         *e;
  12. {
  13.     ESTRUC_
  14.         *a;
  15.     register unsigned
  16.         index,
  17.         n_pars;
  18.     unsigned
  19.         err,
  20.         old_sem;
  21.  
  22.     if (x != funtab.n_defined)              /* function name found ? */
  23.     {                                       /* then check correct # of args */
  24.         n_pars = funtab.symbol[x].var.vu.i->ls.list.size;
  25.         if ((unsigned)e->type != n_pars)
  26.         {
  27.             err = 1;
  28.             semantic("Function '%s()' requires %u arguments",
  29.                         funtab.symbol[x].name, n_pars);
  30.         }
  31.         else
  32.         {                                   /* and check argument types */
  33.             for
  34.             (
  35.                 err = 0,
  36.                 a = (ESTRUC_ *)e->code,
  37.                 index = 0;
  38.                     index < n_pars;
  39.                         index++,
  40.                         a++
  41.             )
  42.             {
  43.                 if
  44.                 (
  45.                     !
  46.                     (
  47.                         ((char *)
  48.                            funtab.symbol[x].var.vu.i->ls.list.element)[index]
  49.                         & a->type & ALLTYPES
  50.                     )
  51.                 )
  52.                 {
  53.                     old_sem = sem_err;
  54.                     err = 1;
  55.                     semantic("Incorrect type of argument %u of function '%s()'",
  56.                         index + 1, funtab.symbol[x].name);
  57.                     sem_err = old_sem;
  58.                 }
  59.             }
  60.             sem_err |= err;
  61.         }
  62.     }
  63.     else
  64.         n_pars = 0;                         /* prevent unitialized n_pars */
  65.  
  66.     catargs(e);                             /* convert args to code */
  67.  
  68.                                             /* call function and clean stack */
  69.     gencode(e, op_call, funtab.symbol[x].var.vu.i->count);
  70.     gencode(e, op_asp,  n_pars);
  71.     set_type(e, funtab.symbol[x].var.type);
  72.  
  73.     return (e);                             /* return called function code */
  74. }